import uiautomator2 as u2
import uiautomator2.ext.htmlreport as htmlreport
from time import sleep
import time
import os


# com.bluephone 包名
# d = u2.connect('MT66-2WA-9D06127')  #连接手机
import json
def scan(x):
    os.system("adb shell am broadcast -a android.intent.ACTION_DECODE_DATA --es barcode_string %s" % x)
    time.sleep(1)
d=u2.connect_wifi('192.168.2.213')   #通过wifi连接，ip为手机的ip
d.screen_on()  # 打开屏幕
# d.screen_off()  #关闭屏幕
# print(d.window_size())  #获取屏幕大小
# print(d.wlan_ip)    #获取wifi地址
d.app_start("com.bluephone")
# print(d.window_size())  #获取基本信息
scan("9999010001A1001")
d(resourceId="com.bluephone:id/depart_name").click()
d.send_keys("001", clear=True)
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
d(resourceId="com.bluephone:id/doctors_name").click()
d.send_keys("001", clear=True)
d(resourceId="com.bluephone:id/md_buttonDefaultPositive").click()
scan("9999010001B1048")  # 扫自动化科室


info1=d.info
info2=d.device_info   #获取详细的设备信息，selected和enable
info3=(d(resourceId="com.bluephone:id/depart_name").info['selected'])   #selected的状态False或True
print(info3)


d.app_current()  # 获取前台应用 packageName, activity
# d.press('recent')   #打开任务管理器
# d.swipe(0.764, 0.465,0.156, 0.474)  #左滑动关闭
# d.press('left')